<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="采购方总部编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchaserHqCode', validatorRules.purchaserHqCode]" placeholder="请输入采购方总部编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入供应商编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierName', validatorRules.supplierName]" placeholder="请输入供应商名称"></a-input>
        </a-form-item>
        <a-form-item label="生产工单编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'woNo', validatorRules.woNo]" placeholder="请输入生产工单编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商生产订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ipoNo', validatorRules.ipoNo]" placeholder="请输入供应商生产订单编号"></a-input>
        </a-form-item>
        <a-form-item label="品类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categoryCode', validatorRules.categoryCode]" placeholder="请输入品类编码"></a-input>
        </a-form-item>
        <a-form-item label="种类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclassCode', validatorRules.subclassCode]" placeholder="请输入种类编码"></a-input>
        </a-form-item>
        <a-form-item label="厂家物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsCode', validatorRules.materialsCode]" placeholder="请输入厂家物料编码"></a-input>
        </a-form-item>
        <a-form-item label="厂家物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsDescription', validatorRules.materialsDescription]" placeholder="请输入厂家物料描述"></a-input>
        </a-form-item>
        <a-form-item label="物料批次" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsBatch', validatorRules.materialsBatch]" placeholder="请输入物料批次"></a-input>
        </a-form-item>
        <a-form-item label="生产数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'amount', validatorRules.amount]" placeholder="请输入生产数量"></a-input>
        </a-form-item>
        <a-form-item label="计量单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'unit', validatorRules.unit]" placeholder="请输入计量单位"></a-input>
        </a-form-item>
        <a-form-item label="计划开始日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择计划开始日期" v-decorator="[ 'planStartDate', validatorRules.planStartDate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="计划完成日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择计划完成日期" v-decorator="[ 'planFinishDate', validatorRules.planFinishDate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="实际开始日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择实际开始日期" v-decorator="[ 'actualStartDate', validatorRules.actualStartDate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="实际完成日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择实际完成日期" v-decorator="[ 'actualFinishDate', validatorRules.actualFinishDate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="工单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'woStatus', validatorRules.woStatus]" placeholder="请输入工单状态"></a-input>
        </a-form-item>
        <a-form-item label="实物ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'entityCode', validatorRules.entityCode]" placeholder="请输入实物ID"></a-input>
        </a-form-item>
        <a-form-item label="工艺路线编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processRouteNo', validatorRules.processRouteNo]" placeholder="请输入工艺路线编码"></a-input>
        </a-form-item>
        <a-form-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSource', validatorRules.dataSource]" placeholder="请输入数据来源"></a-input>
        </a-form-item>
        <a-form-item label="来源数据创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择来源数据创建时间" v-decorator="[ 'dataSourceCreateTime', validatorRules.dataSourceCreateTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="数据拥有方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ownerId', validatorRules.ownerId]" placeholder="请输入数据拥有方"></a-input>
        </a-form-item>
        <a-form-item label="数据可见方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'openId', validatorRules.openId]" placeholder="请输入数据可见方"></a-input>
        </a-form-item>
        <a-form-item label="逻辑删除" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'isDeleted', validatorRules.isDeleted]" placeholder="请输入逻辑删除"></a-input>
        </a-form-item>
        <a-form-item label="更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'modifyTime', validatorRules.modifyTime]" placeholder="请输入更新时间"></a-input>
        </a-form-item>
        <a-form-item label="产品型号规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'modelSpec', validatorRules.modelSpec]" placeholder="请输入产品型号规格"></a-input>
        </a-form-item>
        <a-form-item label="状态表示" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入状态表示"></a-input>
        </a-form-item>
        <a-form-item label="错误信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'message', validatorRules.message]" placeholder="请输入错误信息"></a-input>
        </a-form-item>
        <a-form-item label="本条数据是新增/更新" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'status', validatorRules.status]" placeholder="请输入本条数据是新增/更新"></a-input>
        </a-form-item>
        <a-form-item label="全局流水号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'transno', validatorRules.transno]" placeholder="请输入全局流水号"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "EipWorkOrderModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        puid:{rules: [{ required: true, message: '请输入全库唯一码!' }]},
        purchaserHqCode:{rules: [{ required: true, message: '请输入采购方总部编码!' }]},
        supplierCode:{rules: [{ required: true, message: '请输入供应商编码!' }]},
        supplierName:{rules: [{ required: true, message: '请输入供应商名称!' }]},
        woNo:{rules: [{ required: true, message: '请输入生产工单编码!' }]},
        ipoNo:{rules: [{ required: true, message: '请输入供应商生产订单编号!' }]},
        categoryCode:{rules: [{ required: true, message: '请输入品类编码!' }]},
        subclassCode:{rules: [{ required: true, message: '请输入种类编码!' }]},
        materialsCode:{rules: [{ required: true, message: '请输入厂家物料编码!' }]},
        materialsDescription:{},
        materialsBatch:{},
        amount:{rules: [{ required: true, message: '请输入生产数量!' }]},
        unit:{rules: [{ required: true, message: '请输入计量单位!' }]},
        planStartDate:{rules: [{ required: true, message: '请输入计划开始日期!' }]},
        planFinishDate:{rules: [{ required: true, message: '请输入计划完成日期!' }]},
        actualStartDate:{},
        actualFinishDate:{},
        woStatus:{rules: [{ required: true, message: '请输入工单状态!' }]},
        entityCode:{},
        processRouteNo:{},
        dataSource:{rules: [{ required: true, message: '请输入数据来源!' }]},
        dataSourceCreateTime:{rules: [{ required: true, message: '请输入来源数据创建时间!' }]},
        ownerId:{},
        openId:{},
        isDeleted:{rules: [{ required: true, message: '请输入逻辑删除!' }]},
        modifyTime:{},
        modelSpec:{},
        ioflag:{},
        message:{},
        status:{},
        transno:{},
        remark1:{},
        remark2:{},
        remark3:{},
        remark4:{},
        remark5:{},
        },
        url: {
          add: "/pg/eipWorkOrder/add",
          edit: "/pg/eipWorkOrder/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'puid','purchaserHqCode','supplierCode','supplierName','woNo','ipoNo','categoryCode','subclassCode','materialsCode','materialsDescription','materialsBatch','amount','unit','planStartDate','planFinishDate','actualStartDate','actualFinishDate','woStatus','entityCode','processRouteNo','processrevision','dataSource','dataSourceCreateTime','ownerId','openId','isDeleted','modifyTime','modelSpec','ioflag','message','status','transno','remark1','remark2','remark3','remark4','remark5'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.puid){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.errorCode==0){
                that.$message.success(res.data);
                that.$emit('ok');
              }else{
                that.$message.warning(res.data);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'puid','purchaserHqCode','supplierCode','supplierName','woNo','ipoNo','categoryCode','subclassCode','materialsCode','materialsDescription','materialsBatch','amount','unit','planStartDate','planFinishDate','actualStartDate','actualFinishDate','woStatus','entityCode','processRouteNo','processrevision','dataSource','dataSourceCreateTime','ownerId','openId','isDeleted','modifyTime','modelSpec','ioflag','message','status','transno','remark1','remark2','remark3','remark4','remark5'))
      }
      
    }
  }
</script>